using UnityEngine;

namespace Script.StateMachine
{
    public class AttackState:IState
    {
        private FSM manager;
        private Parameter _parameter;
        private AnimatorStateInfo _info;
        public AttackState(FSM manager)
        {
            this.manager = manager;
            _parameter = manager.parameter;
        }

        public void OnEnter()
        {
            manager.animator.Play("Attack");
        }
        public void OnUpdate()
        {
            manager.Flip(_parameter.playerTrans);

            if (_parameter.isHit)
            {
                manager.TransitionState(StateType.Hit);
            }
            
            _info = manager.animator.GetCurrentAnimatorStateInfo(0);
            if (_info.normalizedTime>0.99 && 
                !Physics2D.OverlapCircle(_parameter.attackPoint.position, _parameter.attackArea, _parameter.targetLayer))
            {
                manager.TransitionState(StateType.Chase);
            }
        }
        public void OnExit()
        {
        }
    }
}